package com.health.fragment.focusgroup.maternity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.viewscontrols.FWMYDPJActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.viewscontrols.focusgroup.MaternityActivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.GRAVIDA_BASEINFO;
import com.health.tablebean.GRAVIDA_POSTPARTUM;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;
import com.novabluetooth.services.BluetoothConstant;
import com.novabluetooth.views.ExamHistoryActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * 重点人群-- 孕妇---产后访视
 * 
 * @author nova
 *
 */
public class Maternity_ChfsFragment extends NovaFragment implements onFragmentSave, OnClickListener {
	private View cqsf2View = null;
	private FDbManager fdbmanger = null;

	// ------------------------------基本信息-----------------------------
	private EditTextWithDate ed_date;
	private EditText ed_tw;

	private Button btn_choose_tw;// 选择体温

	private EditText ed_ybjkzk;// 一般精神状况
	private EditText ed_ybxlzk;// 一般心理状况
	private EditText ed_xy;// 血压
	private Button btn_choose_xy;

	private EditText ed_qt;// 其他

	private MyGridView gd_rf;// 乳房
	private MyGridView gd_el;// 恶露
	private MyGridView gd_zg;// 子宫
	private MyGridView gd_sk;// 伤口

	private MyGridView gd_fl;// 总体评估
	private MyGridView gd_bjzd;// 保健指导
	private EditText ed_jg_ys;// 机构及科室

	private EditTextWithDate ed_xcsfsj;// 下次随访时间
	private NiceSpinner ed_sfysqm;// 随访医生签名
	// ----------------------------------------------------------------------
	private RadioButtonAdapter adapter_fl = null;
	private RadioButtonAdapter adapter_rf = null;
	private RadioButtonAdapter adapter_el = null;
	private RadioButtonAdapter adapter_zg = null;
	private RadioButtonAdapter adapter_sk = null;

	private CheckBoxAdapter adapter_bjzd = null;

	private TextView tv_name;
	public ARCHIVE_BASEINFO userInfo;
	private RadioGroup rd_zz;// 是否转诊
	private RadioButton rb_w;
	private RadioButton rb_y;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private EditText ed_zzyy;
	private int from_followup = -1;

	private String str_flId = "";
	private String str_flContent = "";
	private String str_rfId = "";
	private String str_rfContent = "";
	private String str_elId = "";
	private String str_elContent = "";
	private String str_zgId = "";
	private String str_zgContent = "";
	private String str_skId = "";
	private String str_skContent = "";

	private String str_zzId = "";

	private String str_zhidaoId = "";
	private String str_zhidaoContent = "";
	private EditTextWithDate ed_date_fm;//分娩时间
	private EditTextWithDate ed_date_cy;//出院时间
	private TextView tv_cc;//产次
	private GRAVIDA_BASEINFO gravida_baseInfo= NovaApplication.gravida_baseInfo;// 孕妇信息

	@Override
	public View findViews(LayoutInflater inflater) {
		fdbmanger = NovaApplication.fdbmanger;
		userInfo = NovaApplication.getUserInfo();
		cqsf2View = inflater.inflate(R.layout.maternity_chfs, null);
		GlobalConts.setMaxLength(50, ed_ybjkzk, // 一般精神状况
				ed_ybxlzk// 一般心理状况
				, ed_qt);
		GlobalConts.setMaxLength(20, ed_xy);// 血压

		// 乳房
		// 恶露
		// 子宫
		// 伤口
		// 其他
		// 分类
		// 指导
		// 转诊50

		initViews(cqsf2View);

		//添加 DeliveryTime分娩时间  DischargeTime出院时间
		NovaApplication.dbManger.addColumnByBySQL("GRAVIDA_POSTPARTUM", "DeliveryTime");
		NovaApplication.dbManger.addColumnByBySQL("GRAVIDA_POSTPARTUM", "DischargeTime");
		return cqsf2View;
	}

	/**
	 * 初始化布局
	 * 
	 * @param v
	 * @author 王婷婷
	 * @date 2015年12月21日 上午11:10:55
	 */
	private void initViews(View v) {
		tv_name = (TextView) v.findViewById(R.id.tv_name);
		tv_name.setText("姓名：" + userInfo.getCUSTOMERNAME());
		ed_date = (EditTextWithDate) v.findViewById(R.id.ed_date);
		ed_date.setBefore(true);

		ed_date_fm = (EditTextWithDate) v.findViewById(R.id.ed_date_fm);
		ed_date_cy = (EditTextWithDate) v.findViewById(R.id.ed_date_cy);
		ed_tw = (EditText) v.findViewById(R.id.ed_tw);
		btn_choose_tw = (Button) v.findViewById(R.id.btn_choose_tw);
		ed_xy = (EditText) v.findViewById(R.id.ed_xy);
		btn_choose_xy = (Button) v.findViewById(R.id.btn_choose_xy);

		ed_ybjkzk = (EditText) v.findViewById(R.id.ed_ybjkzk);
		ed_ybxlzk = (EditText) v.findViewById(R.id.ed_ybxlzk);
		ed_qt = (EditText) v.findViewById(R.id.ed_qt);
		gd_fl = (MyGridView) v.findViewById(R.id.gd_ztpg);
		gd_bjzd = (MyGridView) v.findViewById(R.id.gd_bjzd);
		ed_jg_ys = (EditText) v.findViewById(R.id.ed_jg_ys);

		ed_xcsfsj = (EditTextWithDate) v.findViewById(R.id.ed_xcsfsj);
		ed_sfysqm = (NiceSpinner) v.findViewById(R.id.ed_sfysqm);

		ed_zzyy = (EditText) v.findViewById(R.id.ed_zzyy);

		gd_rf = (MyGridView) v.findViewById(R.id.gd_rf);
		gd_el = (MyGridView) v.findViewById(R.id.gd_el);

		gd_zg = (MyGridView) v.findViewById(R.id.gd_zg);
		gd_sk = (MyGridView) v.findViewById(R.id.gd_sk);
		rd_zz = (RadioGroup) v.findViewById(R.id.rd_zz);
		rb_w = (RadioButton) v.findViewById(R.id.rb_w);
		rb_y = (RadioButton) v.findViewById(R.id.rb_y);
		tv_cc = (TextView) v.findViewById(R.id.tv_cc);
		ed_zzyy.setEnabled(false);
		ed_jg_ys.setEnabled(false);
	}

	/**
	 * 绑定数据值
	 * 
	 * @param str_where
	 * @param flag
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:30:30
	 */
	private void bindDdata(String flag, String str_where) {
		List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
				str_where + " order by cast(SORT as int) asc");

		if (flag.equals("总体评估")) {
			adapter_fl = new RadioButtonAdapter(listZZs, getActivity());
			adapter_fl.setOtherMaxLength(50);
			gd_fl.setAdapter(adapter_fl);

			// 乳房
			adapter_rf = new RadioButtonAdapter(listZZs, getActivity());
			adapter_rf.setOtherMaxLength(50);
			gd_rf.setAdapter(adapter_rf);

			// 恶露
			adapter_el = new RadioButtonAdapter(listZZs, getActivity());
			adapter_el.setOtherMaxLength(50);
			gd_el.setAdapter(adapter_el);

			// 子宫
			adapter_zg = new RadioButtonAdapter(listZZs, getActivity());
			adapter_zg.setOtherMaxLength(50);
			gd_zg.setAdapter(adapter_zg);

			// 伤口
			adapter_sk = new RadioButtonAdapter(listZZs, getActivity());
			adapter_sk.setOtherMaxLength(50);
			gd_sk.setAdapter(adapter_sk);

		} else if (flag.equals("保健指导")) {

			List<BD_DD_INFO> listZZs_new = new ArrayList<BD_DD_INFO>();
			int size = listZZs.size();
			if (size > 0) {
				for (int i = 0; i < size; i++) {

					// 个人卫生 DM06-03_1 、 心理 DM06-03_2 、膳食DM06-03_3、运动
					// DM06-03_6、其他 DM06-03_99、DM06-03_14 营养
					if (listZZs.get(i).getID().equals("DM06-03_1") || listZZs.get(i).getID().equals("DM06-03_2")
							|| listZZs.get(i).getID().equals("DM06-03_14") || listZZs.get(i).getID().equals("DM06-03_9")
							|| listZZs.get(i).getID().equals("DM06-03_10")
							|| listZZs.get(i).getID().equals("DM06-03_99")) {
						listZZs_new.add(listZZs.get(i));
					}
				}
			}
			adapter_bjzd = new CheckBoxAdapter(getActivity(), listZZs_new);
			adapter_bjzd.setOtherMaxLength(50);
			gd_bjzd.setAdapter(adapter_bjzd);
		}
	}

	@Override
	public void setupView(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void addListener() {
		rd_zz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				if (checkedId == R.id.rb_w) {
					str_zzId = "DM01-11_1";
					ed_zzyy.setText("");
					ed_jg_ys.setText("");
					ed_zzyy.setEnabled(false);
					ed_jg_ys.setEnabled(false);

				} else if (checkedId == R.id.rb_y) {
					str_zzId = "DM01-11_2";
					ed_zzyy.setEnabled(true);
					ed_jg_ys.setEnabled(true);
				} else {
					str_zzId = "";
				}

			}
		});
		btn_choose_xy.setOnClickListener(this);
		btn_choose_tw.setOnClickListener(this);
	}

	@Override
	public void setData() {
		List<GRAVIDA_BASEINFO> gradicas = fdbmanger.findAllByWhere(GRAVIDA_BASEINFO.class,
				"IDCARD = '" + userInfo.getIDCARD()+"'");
		if (gradicas.size() > 0) {
			gravida_baseInfo = gradicas.get(0);
		}
		checkFetusTime();
		GlobalConts.doctorList( ed_sfysqm);
		bindDdata("转诊", "PARENTID='DM01-11'");
		bindDdata("总体评估", "PARENTID='DM01-40'");
		bindDdata("保健指导", "PARENTID='DM06-03'");
		setData_followUP();
		setDateCheck();
	}

	/**
	 * 检查是否已经填写孕次
	 */
	private void checkFetusTime() {
		List<GRAVIDA_BASEINFO> gradicas = fdbmanger.findAllByWhere(GRAVIDA_BASEINFO.class,
				"IDCARD = '" + userInfo.getIDCARD()+"'");
		if (gradicas.size() > 0) {
			if (TextUtils.isEmpty(gradicas.get(0).getFetusTimes())){
				((MaternityActivity) getActivity()).showTextDialog("请先完善基本信息中的产次信息再进行随访操作");
				return;
			}else{
				List<BD_DD_INFO> bd_cc = getBDById(gravida_baseInfo.getFetusTimes());
				if (bd_cc != null) {
					tv_cc.setText(bd_cc.get(0).getDATAINFO());
				}

			}
		}else{
			((MaternityActivity) getActivity()).showTextDialog("请先完善基本信息再进行随访操作");
			return;
		}
	}

	/**
	 * 通过id查询返回的数据
	 *
	 * @param str_id
	 * @return
	 * @author 王婷婷
	 * @date 2015年12月15日 下午6:38:52
	 */
	private List<BD_DD_INFO> getBDById(String str_id) {
		if (str_id != null) {

			List<BD_DD_INFO> bds = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, "ID='" + str_id + "'");
			if (bds.size() > 0) {

				return bds;
			} else {
				return null;
			}
		} else {
			return null;
		}

	}

	/**
	 * 设置验证展示
	 * 
	 * @author 王婷婷
	 * @date 2016年2月3日 上午10:49:40
	 */
	private void setDateCheck() {
		// 设置时间
		GlobalConts.checkDateAfter(ed_date, ed_xcsfsj);
		// 体温
		GlobalConts.keep2decimal(ed_tw);
		GlobalConts.checkNum(getActivity(), ed_tw, 37.3, 36, 99);
	}

	@Override
	public void save() {
		checkFetusTime();
		// 体温
		String TEM = ed_tw.getText().toString();
		if (TextUtils.isEmpty(TEM)) {
			ed_tw.setBackgroundColor(Color.YELLOW);
			((MaternityActivity) getActivity()).showTextDialog("请填写体温");
			return;
		} else {
			if (!GlobalConts.getCheckNumBoolean(getActivity(), ed_tw, 37.3, 36, 99)) {
				ed_tw.setBackgroundColor(Color.YELLOW);
				((MaternityActivity) getActivity()).showTextDialog("体温数据不合理，保存失败");
				return;
			}
			ed_tw.setBackgroundColor(Color.WHITE);
		}

		String str_xy = ed_xy.getText().toString();
		if (TextUtils.isEmpty(str_xy)) {
			ed_xy.setBackgroundColor(Color.YELLOW);
			((MaternityActivity) getActivity()).showTextDialog("请填写血压");
			return;
		} else {
			if (!str_xy.contains("/")) {
				ed_xy.setBackgroundColor(Color.YELLOW);
				((MaternityActivity) getActivity()).showTextDialog("血压数据不合理，保存失败");
				return;
			}
			ed_xy.setBackgroundColor(Color.WHITE);
		}
		// 下次随访时间
		String str_xcsfsj = ed_xcsfsj.getText().toString();
		if (TextUtils.isEmpty(str_xcsfsj)) {
			ed_xcsfsj.setBackgroundColor(Color.YELLOW);
			((MaternityActivity) getActivity()).showTextDialog("请选择下次随访时间");
			return;
		} else {
			ed_xcsfsj.setBackgroundColor(Color.WHITE);
		}

		getRadioButtonCheckedData();
		getCheckBoxedData();
		saveData_followup();
	}

	/**
	 * 获取转诊的信息
	 * 
	 * @author 王婷婷
	 * @date 2015年12月16日 下午3:10:48
	 */
	private void getRadioButtonCheckedData() {

		str_flId = adapter_fl.getChecked();
		str_flContent = adapter_fl.getCheckedOther();
		str_rfId = adapter_rf.getChecked();
		str_rfContent = adapter_rf.getCheckedOther();
		str_elId = adapter_el.getChecked();
		str_elContent = adapter_el.getCheckedOther();
		str_zgId = adapter_zg.getChecked();
		str_zgContent = adapter_zg.getCheckedOther();
		str_skId = adapter_sk.getChecked();
		str_skContent = adapter_sk.getCheckedOther();

	}

	/**
	 * 获取 被选中的checkbox
	 * 
	 * @author 王婷婷
	 * @date 2015年12月19日 上午11:34:30
	 */
	private void getCheckBoxedData() {
		str_zhidaoId = adapter_bjzd.getCheckedIdsStr();
		str_zhidaoContent = adapter_bjzd.getOther();

	}

	/**
	 * 保存数据
	 * 
	 * @author 王婷婷
	 * @date 2015年12月17日 上午11:13:39
	 */
	private void saveData_followup() {

		GRAVIDA_POSTPARTUM ques = new GRAVIDA_POSTPARTUM();

		ques.setIDCARD(userInfo.getIDCARD());
		ques.setARCHIVEID("");// 设置档案编号

		String str_ed_time1_start = ed_date.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time1_start)) {
			try {
				ques.setFOLLOWUP_DATE((Date) dateFormat.parse(str_ed_time1_start));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		String str_ed_time_fm = ed_date_fm.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time_fm)) {
			try {
				ques.setDeliveryTime((Date) dateFormat.parse(str_ed_time_fm));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		String str_ed_time_cy = ed_date_cy.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time_cy)) {
			try {
				ques.setDischargeTime((Date) dateFormat.parse(str_ed_time_cy));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		String str_ed_time_next = ed_xcsfsj.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time_next)) {
			try {
				ques.setNEXTFOLLOWUP_DATE((Date) dateFormat.parse(str_ed_time_next));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		ques.setTEM(ed_tw.getText().toString());

		ques.setHEALTHCONDITION(ed_ybjkzk.getText().toString());
		ques.setMENTALCONDITION(ed_ybxlzk.getText().toString());

		String str_xy = ed_xy.getText().toString();
		if (!TextUtils.isEmpty(str_xy)) {
			if (str_xy.contains("/")) {
				ques.setHBLOODPRESSURE(str_xy.split("/")[0]);// 收缩压
				ques.setLBLOODPRESSURE(str_xy.split("/")[1]);// 舒张压
			} else {
				ques.setHBLOODPRESSURE("");// 收缩压
				ques.setLBLOODPRESSURE("");// 舒张压
			}
		} else {
			ques.setHBLOODPRESSURE("");// 收缩压
			ques.setLBLOODPRESSURE("");// 舒张压
		}

		//
		// ques.setHBLOODPRESSURE(0);// 收缩压
		// ques.setLBLOODPRESSURE(0);// 舒张压

		ques.setBREAST(str_rfId);
		ques.setBREAST_EX(str_rfContent);

		ques.setLOCHIA(str_elId);
		ques.setLOCHIA_EX(str_elContent);

		ques.setUTERUS(str_zgId);
		ques.setUTERUS_EX(str_zgContent);

		ques.setWOUND(str_skId);
		ques.setWOUND_EX(str_skContent);

		ques.setOTHER(ed_qt.getText().toString());

		ques.setCLASSIFICATION(str_flId);
		ques.setCLASSIFICATION_EX(str_flContent);

		ques.setADVISING(str_zhidaoId);
		ques.setADVISINGOTHER(str_zhidaoContent);

		if (rb_w.isChecked()) {
			str_zzId = "DM01-11_1";
		} else if (rb_y.isChecked()) {
			str_zzId = "DM01-11_2";
		} else {
			str_zzId = "";
		}

		ques.setREFERRAL(str_zzId);
		ques.setREFERRALREASON(ed_zzyy.getText().toString());
		ques.setREFERRALORG(ed_jg_ys.getText().toString());
		ques.setFOLLOWUPDOCTOR(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
		ques.setIS_DEL("N");
		ques.setIS_UPDATE("Y");
		ques.setLAST_UPDATE_DATE(new Date());
		ques.setLAST_UPDATE_BY(NovaApplication.getDoctorList() .get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
		if (from_followup == 1) {
			ques.setUPDATEORG(userInfo.getCREATEORG());
			ques.setMODIFIED(NovaApplication.getDoctorList().get(ed_sfysqm.getSelectedIndex()).getUSER_ID());
			fdbmanger.updata(ques, "IDCARD='" + userInfo.getIDCARD() + "'");
		} else {

			ques.setCREATED_DATE(new Date());
			ques.setCREATEORG(userInfo.getCREATEORG());
			ques.setCREATER(userInfo.getCREATER());
			ques.setCREATED_BY(userInfo.getCREATED_BY());
			fdbmanger.save(ques);
			from_followup = 1;
		}
//		((MaternityActivity) getActivity()).showTextDialog("保存成功");
		if (GlobalConts.TYPE_JTYS.equals(NovaApplication.getType())) {
			new AlertDialog.Builder(getActivity()).setTitle("保存成功").setMessage("进行满意度评价")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							Intent intent = new Intent(getContext(), FWMYDPJActivity.class);
							intent.putExtra("type", "04");
							intent.putExtra("szfs","");
							startActivity(intent);
						}
					}).show();
		} else if (GlobalConts.TYPE_GJJBGGWS.equals(NovaApplication.getType())) {
			((MaternityActivity) getActivity()).showTextDialog("保存成功");
		}

	}

	/**
	 * 设置 显示followup
	 * 
	 * @author 王婷婷
	 * @date 2015年12月24日 下午2:25:11
	 */
	private void setData_followUP() {
		List<GRAVIDA_POSTPARTUM> queses = fdbmanger.findAllByWhere(GRAVIDA_POSTPARTUM.class,
				"IDCARD='" + userInfo.getIDCARD() + "'");
		int size = queses.size();
		if (size > 0) {
			from_followup = 1;

			GRAVIDA_POSTPARTUM ques1 = queses.get(0);

			if (ques1.getFOLLOWUP_DATE() != null) {
				try {
					ed_date.setText(dateFormat.format(ques1.getFOLLOWUP_DATE()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			if (ques1.getDeliveryTime() != null) {
				try {
					ed_date_fm.setText(dateFormat.format(ques1.getDeliveryTime()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			if (ques1.getDischargeTime() != null) {
				try {
					ed_date_cy.setText(dateFormat.format(ques1.getDischargeTime()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			if (ques1.getNEXTFOLLOWUP_DATE() != null) {
				try {
					ed_xcsfsj.setText(dateFormat.format(ques1.getNEXTFOLLOWUP_DATE()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			ed_tw.setText(ques1.getTEM());

			ed_ybjkzk.setText(ques1.getHEALTHCONDITION());
			ed_ybxlzk.setText(ques1.getMENTALCONDITION());

			String sys_ss = ques1.getHBLOODPRESSURE();
			if (!TextUtils.isEmpty(sys_ss)) {
				String sys_sz = ques1.getLBLOODPRESSURE();
				String str_sy = sys_ss + "/" + sys_sz;
				ed_xy.setText(str_sy);
			}

			str_rfId = ques1.getBREAST();
			str_rfContent = ques1.getBREAST_EX();
			adapter_rf.setChecked(str_rfId, str_rfContent);

			str_elId = ques1.getLOCHIA();
			str_elContent = ques1.getLOCHIA_EX();
			adapter_el.setChecked(str_elId, str_elContent);

			str_zgId = ques1.getUTERUS();
			str_zgContent = ques1.getUTERUS_EX();
			adapter_zg.setChecked(str_zgId, str_zgContent);

			str_skId = ques1.getWOUND();
			str_skContent = ques1.getWOUND_EX();
			adapter_sk.setChecked(str_skId, str_skContent);

			str_flId = ques1.getCLASSIFICATION();
			str_flContent = ques1.getCLASSIFICATION_EX();
			adapter_fl.setChecked(str_flId, str_flContent);

			ed_qt.setText(ques1.getOTHER());

			str_zhidaoId = ques1.getADVISING();
			str_zhidaoContent = ques1.getADVISINGOTHER();
			adapter_bjzd.setChecked(str_zhidaoId);
			adapter_bjzd.setOther(str_zhidaoContent);

			str_zzId = ques1.getREFERRAL();

			if (!TextUtils.isEmpty(str_zzId)) {
				if (str_zzId.equals("DM01-11_1")) {
					rb_w.setChecked(true);
				} else if (str_zzId.equals("DM01-11_2")) {
					rb_y.setChecked(true);
				}
			}

			ed_zzyy.setText(ques1.getREFERRALREASON());
			ed_jg_ys.setText(ques1.getREFERRALORG());
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (ques1.getFOLLOWUPDOCTOR().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_sfysqm.setSelectedIndex(i);
				}

			}

		} else {
			from_followup = 0;
			ed_date.setText(dateFormat.format(new Date()));
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (userInfo.getCREATED_BY().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_sfysqm.setSelectedIndex(i);
				}

			}
		}
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(getActivity(), ExamHistoryActivity.class);
		int id = v.getId();
		if (id == R.id.btn_choose_xy) {
			intent.putExtra("flag", BluetoothConstant.XUEYA_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestXueya);
		} else if (id == R.id.btn_choose_tw) {
			intent.putExtra("flag", BluetoothConstant.TIWEN_TYPENAME);
			getActivity().startActivityForResult(intent, GlobalConts.RequestTiwen);
		} else {
		}

	}

	@Override
	public void setTiWen(String tiwen) {
		Log.w("ddddddddddd", tiwen);
		ed_tw.setText(tiwen);
	}

	@Override
	public void setXueya(String gaoya, String diya, String mailv) {
		ed_xy.setText(gaoya + "/" + diya);
	}
}
